//
//  DeviceModel.m
//  Fotile
//
//  Created by AllenKwok on 16/5/24.
//  Copyright © 2016年 xlink.cn. All rights reserved.
//

#import "DeviceModel.h"
#import "NSTools.h"
#import "RecvAndSendPacketTool.h"
#import "FTSmartDeviceConst.h"

@implementation DeviceModel{
    NSString *_name;
}

- (BOOL)isEqual:(id)other{
    if (other == self) {
        return YES;
    }else {
        DeviceModel *otherDevice = (DeviceModel *)other;
        return [self.deviceEntity.macAddress isEqualToData:otherDevice.deviceEntity.macAddress];
    }
}

-(void)cancelTask{
    
}
/**
 返回一个设备实体 初始化，设备具体产品形态，套系名称
 
 @param pid 设备的产品ID
 @return 具体设备实体类型
 */
DeviceModel *FTSmartDeviceWithProductID(NSString *pid) {
    __block DeviceModel *model;
    if (FTProductIDS().count != FTModelNameArray().count) {
        /// 错误 数据状态不匹配
        abort();
        return nil;
    }
    if (![pid isKindOfClass:[NSString class]]) {
        return nil;
    }
    if (!pid || [pid isEqualToString:@""] || pid.length < 32) {
        return nil;
    }
    NSIndexPath *indexPath = FTSmartDeviceIndex(pid);
    if (indexPath) {
        Class cls = NSClassFromString(FTModelNameArray()[indexPath.section][indexPath.row]);
        model = [[cls alloc]init];
        model.deviceSuitType = indexPath.row;
    }
    
    return model;
}

#pragma mark - 初始化方法
-(instancetype)init{
    if (self = [super init]) {
        _role = @(0);
        _isSubscription = @(0);
    }
    return self;
}

- (void)initWithPayload:(NSData *)payload{
    
}


/**
 通过产品PID实例化数据模型，方式2

 @param pid 产品ID
 @return 初始化设备模型
 */
- (instancetype)initWithProductID:(NSString *)pid{
    DeviceModel *model;
    
    model =  FTSmartDeviceWithProductID(pid);
    if (!model) {
        model = [[DeviceModel alloc] init];
    }
    model.productId = pid;
    return model;
}

#pragma mark -YYModel handle the place
/// 返回一个 Dict，将 Model 属性名对映射到 JSON 的 Key。
+ (NSDictionary *)modelCustomPropertyMapper {
    return @{
             @"deviceId"  : @[@"id",@"deviceID"],
             @"mac"       : @[@"macAddress",@"mac"],
             @"productId" : @[@"product_id",@"productID"],
             @"addDate"   : @"active_date",
             @"accessKey" : @[@"access_key",@"accessKey"],
             @"version"   : @"protocolVersion",
             @"lastUseDate"     : @"last_login",
             @"firmwareVersion" : @"firmware_version"
             };
}

/// Dic -> model
- (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic {
    NSDateFormatter *formatter1 = [[NSDateFormatter alloc] init];
    formatter1.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
    formatter1.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
    formatter1.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
    if (dic[@"active_date"]) {
        if ([dic[@"active_date"] isKindOfClass:[NSString class]]) {
            self.addDate = [[formatter1 dateFromString:dic[@"active_date"]] timeIntervalSince1970];
        }
    }
    if (dic[@"last_login"]) {
        if ([dic[@"last_login"] isKindOfClass:[NSString class]]) {
            self.lastUseDate = [[formatter1 dateFromString:dic[@"last_login"]] timeIntervalSince1970];
        }
    }
    if (_mac) {
       _macData = [NSTools hexToData:_mac];
    }
    NSLog(@"=============%@", dic);
    return YES;
}

/**
 过滤通过字典转换成 模型过滤哪些不转换

 @return 不转化的属性数组
 */
+ (NSArray *)modelPropertyBlacklist {
    return @[@"deviceEntity"];
}

/**
 过滤字典，哪些进行转化

 @return 不在名单的，去除转化
 */
+ (NSArray *)modelPropertyWhitelist {
    return @[
             @"deviceId",
             @"mac",
             @"productId",
             @"addDate",
             @"accessKey",
             @"version",
             @"lastUseDate",
             @"firmwareVersion",
             @"authority"
             ];
}

/**
 *  设置菜谱id
 *
 *  @param data 菜谱id值
 */
- (void)setCurCookbookIDWithData:(NSData *)data{
    uint8_t cookbookId[12];
    [data getBytes:&cookbookId length:data.length];
    int sum = 0;
    NSMutableString *string = [NSMutableString string];
    for (int i = 0; i<12; i++) {
        sum += cookbookId[i];
        [string appendFormat:@"%02x",cookbookId[i]];
    }
    if (sum) {
        self.curCookbookID = string;
    }else{
        self.curCookbookID = @"";
    }
}
/*
 字节数		说明
 4          device id
 32         product id
 1          mac length
 n          mac
 */
///通过网关返回的子设备数据初始化一个子设备
- (instancetype)initWithGatewayRecvData:(NSData *)data {
    NSUInteger deviceId;
    [data getBytes:&deviceId range:NSMakeRange(0, 4)];
    deviceId = CFSwapInt32HostToBig((UInt32)deviceId);

    NSString *productIdStr = [[NSString alloc] initWithData:[data subdataWithRange:NSMakeRange(4, 32)] encoding:NSUTF8StringEncoding];
    UInt8 macLength;
    [data getBytes:&macLength range:NSMakeRange(36, 1)];
    NSString *macStr = [NSTools dataToHex:[data subdataWithRange:NSMakeRange(37, macLength)]];
    NSData *macData = [data subdataWithRange:NSMakeRange(37, macLength)];
    // 设备在线状态
    UInt8 deviceLineStatus = 0;
    if (data.length == 44) {
        [data getBytes:&deviceLineStatus range:NSMakeRange(37 + macLength, 1)];
    }
    
    DeviceModel *model;
    
    model = FTSmartDeviceWithProductID(productIdStr);
    
    if (!model) {
        model = [[DeviceModel alloc]init];
    }
    model.productId = productIdStr;
    model.deviceId = deviceId;
    model.macData = macData;
    model.mac = macStr;
    model.macLength = macLength;
    
    //网关及网关子设备的版本号均为v4
    model.version = 4;
    FTLog(@"devicelineStatus:%d",deviceLineStatus);
    model.subDeviceStatus = deviceLineStatus;
    
    return model;
}



#pragma mark - setter方法重写

-(void)setDeviceName:(NSString *)name{
    _name = name;
}

#pragma mark - getter方法重写

-(NSMutableArray *)promptsInfoArray{
    if (!_promptsInfoArray) {
        _promptsInfoArray = [NSMutableArray array];
    }
    return _promptsInfoArray;
}

-(BOOL)allowSmartCook{
    return [FTAllowSmartCookPIDs() containsObject:self.productId];
}

//- (DeviceType)type{
//    if (_type ==0) {
//        for (int i = 0; i<FTProductIDS().count; i++) {
//            if ([_deviceEntity.productID isEqualToString:FTProductIDS()[i]]) {
//                _type = i+1;
//            }
//        }
//        if(_type ==0&&_type==FTProductIDS().count-1){
//            _type = 0x10;
//        }
//        if(_type ==0&&_type==FTProductIDS().count){
//            _type = 0x11;
//        }
//    }
//    
//    return _type;
//}

-(NSString *)name{
    if (_name.length) {
        return _name;
    }else{
//        if (_type) {
//            NSArray *modelNameArray = @[@"蒸箱",@"烤箱1",@"微波炉",@"油烟机",@"灶具",@"消毒柜",@"热水器",@"洗碗机",@"净水器",@"",@"",@"",@"",@"",@"",@"蒸微一体机",@"大厨管家"];
//            NSString *name = modelNameArray[_type-1];
//            if (name.length) {
//                _name = name;
//                return name;
//            }
//        }
        /// 遍历名字
        for (int i = 0;i<FTProductIDS().count; i++) {
            NSArray *suitType = FTProductIDS()[i];
            for (int j = 0; j < suitType.count; j ++) {
                if ([self.productId isEqualToString:suitType[j]]) {
                    NSString *name = FTProductNameArray()[i][j];
                    _name = name;
                    return name;
                }
            }
        }
    }
    return FTSmartLocalizedString(@"SMART_DEVICE_UNKNOWN", nil);
}



-(NSUInteger)deviceId{
    if (_deviceId) {
        return _deviceId;
    }
    if (_deviceEntity && _deviceEntity.deviceID) {
        return _deviceEntity.deviceID;
    }
    return _deviceId;
}

//获取设备的 在线或者 不在线的状态
-(DeviceStutus)deviceStatus{
    
    if (!_deviceEntity.isConnected && !_isVirtualDevice) {
        _deviceStatus = DeviceStutusOffLine;
        return DeviceStutusOffLine;
    }else{
        _deviceStatus = DeviceStutusOnLine;
    }
    return _deviceStatus;
}

- (NSString *)deviceStatusString {
    if (self.isVirtualDevice) {
        return FTSmartLocalizedString(@"SMART_DEVICE_VIRTUAL_NAME", nil);
    }else {
        
        if (self.deviceEntity && self.deviceEntity.isConnected) {
            return FTSmartLocalizedString(@"SMART_DEVICE_ON_LINE", nil);
        }else{
            return FTSmartLocalizedString(@"SMART_DEVICE_OFF_LINE", nil);
        }
    }
}

-(NSString *)iconName{
    NSString *imageName = FTDeviceName(_type);
    if (imageName.length) {
        return [NSString stringWithFormat:@"Kitchenware_%@",imageName];
    }
    return @"";
}

-(NSString *)cookbookIconName{
    NSString *imageName = FTDeviceName(_type);
    if (imageName.length) {
        return [NSString stringWithFormat:@"mine_limit_%@",imageName];
    }
    return @"";
}

-(NSString *)flashImageName{
    NSString *imageName = FTDeviceName(_type);
    if (imageName.length) {
        return [NSString stringWithFormat:@"kitchen_main_%@",imageName];
    }
    return @"";
}

- (NSString *)bgImageName{
    NSString *imageName = FTDeviceName(_type);
    if (imageName.length) {
        return [NSString stringWithFormat:@"kitchen_main_bg_%@",imageName];
    }
    return @"";
}

-(NSString *)cbGgImageName{
    NSString *imageName = FTDeviceName(_type);
    if (imageName.length) {
        return [NSString stringWithFormat:@"kitchen_main_bg_%@",imageName];
    }
    return @"";
}

-(NSString *)mac{
    if (!_mac.length) {
        if (_deviceEntity) {
            _mac = [_deviceEntity getMacAddressSimple];
        }
    }
    return _mac;
}

-(XLDeviceEntity *)deviceEntity {
    if (!_deviceEntity) {
        XLDeviceEntity *entity = [[XLDeviceEntity alloc] init];
        entity.productID = _productId;
        entity.accessKey = _accessKey;
        entity.macAddress = _macData;
        entity.deviceID =(UInt32)_deviceId;
//        entity.version = (int)_version;
        entity.protocolVersion = (int) _version;
        if(entity.protocolVersion < 4) entity.protocolVersion = 4;
#warning the flag update which propery
//        entity.flag = 0b100;
        _deviceEntity = entity;
    }
    return _deviceEntity;
}

#pragma mark - 设备基本控制
//查询设备属性--joemark
- (void)queryDeviceProperty{
    PacketModel *packetModel = [[PacketModel alloc]init];
    packetModel.type = (int)self.type;
    packetModel.command = CommandCodeQueryDeviceStatus;
    packetModel.status = 1;
    [RecvAndSendPacketTool sendPacket:packetModel toDevice:self];
    FTLog(@"%@",[packetModel getData]);
}

- (void)turnOn {
    
}

- (void)turnOff {
    
}

- (void)pause {
    
}

- (void)resume {
    
}



#pragma mark - 菜谱录制
/**
 *  开始菜谱录制
 */
- (void)startCookbookRecordWithCookbookId:(NSString *)cookbookId{
    FTLog(@"cookbookId: Start--%@",cookbookId);
    PacketModel *packModel = [[PacketModel alloc]init];
    packModel.type = self.type;
    packModel.command = CommandCodeStartRecordCookbook;
    packModel.status = 1;
    [packModel configInPayload:[self transformCookbookIdToData:cookbookId]];
    [RecvAndSendPacketTool sendPacket:packModel toDevice:self];
}

/**
 *  结束菜谱录制
 */
-(void)stopCookbookRecordWithCookbookId:(NSString *)cookbookId{
     FTLog(@"cookbookId: Stop--%@",cookbookId);
    PacketModel *packModel = [[PacketModel alloc]init];
    packModel.type = self.type;
    packModel.command = CommandCodeStopRecordCookbook;
    packModel.status = 1;
    [packModel configInPayload:[self transformCookbookIdToData:cookbookId]];
    [RecvAndSendPacketTool sendPacket:packModel toDevice:self];
}

/**
 *  取消菜谱录制
 */
-(void)cancelCookbookRecordWithCookbookId:(NSString *)cookbookId{
    uint8_t status = 1;
    NSMutableData *data = [NSMutableData data];
    [data appendBytes:&status length:1];
    [data appendData:[self transformCookbookIdToData:cookbookId]];
    PacketModel *packModel = [[PacketModel alloc]init];
    packModel.type = self.type;
    packModel.command = CommandCodeCancelRecordCookbook;
    packModel.status = 1;
    [packModel configInPayload:data];
    [RecvAndSendPacketTool sendPacket:packModel toDevice:self];
}


/**
 *  上传录制菜谱
 */
-(void)uploadCookbookDataWithCookbookId:(NSString *)cookbookId{
    PacketModel *packModel = [[PacketModel alloc]init];
    packModel.type = self.type;
    packModel.command = CommandCodeUploadRecordCookbook;
    packModel.status = 1;
    [packModel configInPayload:[self transformCookbookIdToData:cookbookId]];
    [RecvAndSendPacketTool sendPacket:packModel toDevice:self];
}

/**
 *  下载录制菜谱
 */
-(void)downloadCookbookDataWithCookbookId:(NSString *)cookbookId withCookbookData:(NSData *)data{
    NSMutableData *mdata = [NSMutableData dataWithData:[self transformCookbookIdToData:cookbookId]];
    [mdata appendData:data];
    PacketModel *packModel = [[PacketModel alloc]init];
    packModel.type = self.type;
    packModel.command = CommandCodeDownloadRecordCookbook;
    packModel.status = 1;
    [packModel configInPayload:mdata];
    [RecvAndSendPacketTool sendPacket:packModel toDevice:self];
}

//播放本地菜谱
-(void)startLocalCookbookWithCookbookId:(NSString *)cookbookId withLocalId:(uint16_t)localId withPrama:(uint32_t)prama{
    
    NSMutableData *mdata = [NSMutableData data];
    
    uint8_t zero = 0;
    NSData *cidData = [self convertHexStrToData:cookbookId];
    for (int i = 0; i<12-cidData.length; i++) {
        [mdata appendBytes:&zero length:1];
    }
    
    [mdata appendData:cidData];
    uint16_t lid = htons(localId);
    [mdata appendBytes:&lid length:2];
    uint32_t pma = htonl(prama);
    [mdata appendBytes:&pma length:4];
    
    
    PacketModel *packetModel = [[PacketModel alloc]init];
    packetModel.type = (int)self.type;
    packetModel.command = 0x42;
    packetModel.status = 1;
    [packetModel configInPayload:mdata];
    [RecvAndSendPacketTool sendPacket:packetModel toDevice:self];
    FTLog(@"%@",[packetModel getData]);
}

#pragma mark - 灶具专用
/**
 *  开始灶具的菜谱录制
 *
 *  @param cookbookId 菜谱id
 *  @param cookerNum  左右灶标志：0-左灶，1-右灶
 */
- (void)startCookerCookbookRecordWithCookbookId:(NSString *)cookbookId withCooker:(uint8_t)cookerNum{
    [self cookerCookbookControlWithCookbookId:cookbookId withCode:0xff withCooker:cookerNum];
}

/**
 *  开始灶具的菜谱播放
 *
 *  @param cookbookId 菜谱id
 *  @param cookerNum  左右灶标志：0-左灶，1-右灶
 */
- (void)startCookerCookbookPlayWithCookbookId:(NSString *)cookbookId withCooker:(uint8_t)cookerNum{
    [self cookerCookbookControlWithCookbookId:cookbookId withCode:0xfe withCooker:cookerNum];
}

/**
 *  结束灶具的菜谱播放
 *
 *  @param cookbookId 菜谱id
 *  @param cookerNum  左右灶标志：0-左灶，1-右灶
 */
- (void)stopCookerCookbookPlayWithCookbookId:(NSString *)cookbookId withCooker:(uint8_t)cookerNum{
    [self cookerCookbookControlWithCookbookId:cookbookId withCode:0xfd withCooker:cookerNum];
}

/**
 *  灶具
 *
 *  @param cookbookId 菜谱id
 *  @param code       0xfe请求菜谱播放 0xff请求菜谱录制 0xfd请求菜谱播放结束
 *  @param cookerNum  左右灶标志：0-左灶，1-右灶
 */
- (void)cookerCookbookControlWithCookbookId:(NSString *)cookbookId withCode:(uint8_t)code withCooker:(uint8_t)cookerNum{
    NSMutableData *data = [NSMutableData data];
    [data appendData:[self transformCookbookIdToData:cookbookId]];
    [data appendBytes:&code length:1];
    [data appendBytes:&cookerNum length:1];
    PacketModel *packModel = [[PacketModel alloc]init];
    packModel.type = self.type;
    packModel.command = CommandCodeStartCookerRecordCookbook;
    packModel.status = 1;
    [packModel configInPayload:data];
    [RecvAndSendPacketTool sendPacket:packModel toDevice:self];
}

/**
 *  改变菜谱步骤
 *
 *  @param cookbookId 菜谱id
 *  @param step       步骤
 *  @param cookerNum  左右灶标志：0-左灶，1-右灶
 */
- (void)playCookbookWithCookbookId:(NSString *)cookbookId  withStep:(uint8_t)step withCooker:(uint8_t)cookerNum{
    [self cookerCookbookControlWithCookbookId:cookbookId withCode:step withCooker:cookerNum];
}

/**
 *  确认菜谱录制/播放
 *
 *  @param cookbookId 菜谱id
 */
- (void)confirmCookerCookbookRecordWithCookbookId:(NSString *)cookbookId{
    PacketModel *packModel = [[PacketModel alloc]init];
    packModel.type = self.type;
    packModel.command = CommandCodeComfirmCookerRecordCookbook;
    packModel.status = 1;
    [packModel configInPayload:[self transformCookbookIdToData:cookbookId]];
    [RecvAndSendPacketTool sendPacket:packModel toDevice:self];
}

/**
 *  添加标记点
 *
 *  @param cookbookId 菜谱id
 *  @param index      index
 */
- (void)addPromptsWithCookbookId:(NSString *)cookbookId withIndex:(uint8_t)index{
    NSMutableData *data = [NSMutableData data];
    [data appendData:[self transformCookbookIdToData:cookbookId]];
    [data appendBytes:&index length:1];
    PacketModel *packModel = [[PacketModel alloc]init];
    packModel.type = self.type;
    packModel.command = CommandCodeComfirmCookerAddPrompt;
    packModel.status = 1;
    [packModel configInPayload:data];
    [RecvAndSendPacketTool sendPacket:packModel toDevice:self];
}

#pragma mark - tool
- (NSData *)transformCookbookIdToData:(NSString *)cookbookId{
    NSMutableData *mdata = [NSMutableData data];
    
    uint8_t zero = 0;
    NSData *cidData = [self convertHexStrToData:cookbookId];
    for (int i = 0; i<12-cidData.length; i++) {
        [mdata appendBytes:&zero length:1];
    }
    
    [mdata appendData:cidData];
    return mdata;
}

- (NSData *)convertHexStrToData:(NSString *)str {
    if (!str || [str length] == 0) {
        return nil;
    }
    NSMutableData *hexData = [[NSMutableData alloc] initWithCapacity:8];
    NSRange range;
    if ([str length] % 2 == 0) {
        range = NSMakeRange(0, 2);
    } else {
        range = NSMakeRange(0, 1);
    }
    for (NSInteger i = range.location; i < [str length]; i += 2) {
        unsigned int anInt;
        NSString *hexCharStr = [str substringWithRange:range];
        NSScanner *scanner = [[NSScanner alloc] initWithString:hexCharStr];
        
        [scanner scanHexInt:&anInt];
        NSData *entity = [[NSData alloc] initWithBytes:&anInt length:1];
        [hexData appendData:entity];
        
        range.location += range.length;
        range.length = 2;
    }
    
    FTLog(@"hexdata: %@", hexData);
    return hexData;
}

#pragma mark - 设备消息推送

/**
 *  APP发送推送内容给设备
 */
-(void)sendNotifyMessageToDeviceWithContent:(NSString *)content{
    NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
//    mDict[@"from_id"] = FTDATASOURCE.curUser.userId;
//    NSString *name =  FTDATASOURCE.curUser.nickName.length?FTDATASOURCE.curUser.nickName:FTDATASOURCE.curUser.userId.stringValue;
//    if (name.length>9) {
//        name = [name substringToIndex:9];
//    }
//    mDict[@"from_name"]= name;
    mDict[@"type"] = @"notify";
//    mDict[@"content"] = [NSString stringWithFormat:@"%@%@",name,content];
//    if (FTDATASOURCE.curUser.avatar.length) {
//        mDict[@"avatar"] = FTDATASOURCE.curUser.avatar;
//    }
    
    NSData *jsonData = [self transforToJsonString:mDict];//[mDict transforToData];
    uint16_t messageType = 10000;
    NTOHS(messageType);
    NSMutableData *mData = [[NSMutableData alloc]initWithBytes:&messageType length:2];
    [mData appendData:jsonData];
    
    
    PacketModel *packModel = [[PacketModel alloc]init];
    packModel.type = self.type;
    packModel.command = 0xFA;
    packModel.status = 1;
    [packModel configInPayload:mData];
    [RecvAndSendPacketTool sendPacket:packModel toDevice:self];
}

//发送开始远程控制
- (void)sendStartCookNotifyMessage{
    [self sendNotifyMessageToDeviceWithContent:@"进行了远程控制"];
}

//发送开始烹饪消息
- (void)sendStopCookNotifyMessage{
    [self sendNotifyMessageToDeviceWithContent:@"进行了远程控制"];
}

//发送开始预约消息
- (void)sendStartAppointmentNotifyMessage{
    [self sendNotifyMessageToDeviceWithContent:@"开始预约"];
}

//发送结束预约消息
- (void)sendStopAppointmentNotifyMessage{
    [self sendNotifyMessageToDeviceWithContent:@"结束预约"];
}

//发送修改了设置消息
- (void)sendModifySettingNotifyMessage{
    [self sendNotifyMessageToDeviceWithContent:@"修改了设置"];
}


/**
 *  APP发送菜谱推送内容给设备
 */
-(void)sendCookbookNotifyMessageToDeviceWithCookbookName:(NSString *)cookbookName WithContent:(NSString *)content{
    [self sendCookbookNotifyMessageToDeviceWithCookbookName:cookbookName withMessageType:10000 WithContent:content];
}

-(void)sendCookbookNotifyMessageToDeviceWithCookbookName:(NSString *)cookbookName withMessageType:(uint16_t)messageTyppe WithContent:(NSString *)content{
    NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
//    mDict[@"from_id"] = FTDATASOURCE.curUser.userId;
//    NSString *name =  FTDATASOURCE.curUser.nickName.length?FTDATASOURCE.curUser.nickName:FTDATASOURCE.curUser.userId.stringValue;
//    if (name.length>9) {
//        name = [name substringToIndex:9];
//    }
//    mDict[@"from_name"]= name;
    mDict[@"type"] = @"notify";
//    mDict[@"content"] = [NSString stringWithFormat:@"%@%@",name,content];
#warning 暂时屏蔽头像相关
//    if (FTDATASOURCE.curUser.avatar.length) {
//        mDict[@"avatar"] = FTDATASOURCE.curUser.avatar;
//    }
    
    mDict[@"recipe_name"] = cookbookName;

    NSData *jsonData = [self transforToData:mDict];//[mDict transforToData];
    uint16_t type = messageTyppe;
    NTOHS(type);
    NSMutableData *mData = [[NSMutableData alloc]initWithBytes:&type length:2];
    [mData appendData:jsonData];
    
    PacketModel *packModel = [[PacketModel alloc]init];
    packModel.type = self.type;
    packModel.command = 0xFA;
    packModel.status = 1;
    [packModel configInPayload:mData];
    [RecvAndSendPacketTool sendPacket:packModel toDevice:self];
}

//启动菜谱录制通知
- (void)sendStartCookbookRecordNotifyWithCookbookName:(NSString *)cookbookName{
    
    [self sendCookbookNotifyMessageToDeviceWithCookbookName:cookbookName withMessageType:10002 WithContent:@"启动菜谱录制"];
}

//结束菜谱录制通知
- (void)sendStopCookbookRecordNotifyWithCookbookName:(NSString *)cookbookName{
    
    [self sendCookbookNotifyMessageToDeviceWithCookbookName:cookbookName WithContent:@"结束菜谱录制"];
}

//取消菜谱录制通知
- (void)sendCancelCookbookRecordNotifyWithCookbookName:(NSString *)cookbookName{
    [self sendCookbookNotifyMessageToDeviceWithCookbookName:cookbookName WithContent:@"取消菜谱录制"];
}

//启动菜谱播放通知
- (void)sendStartCookbookPlayNotifyWithCookbookName:(NSString *)cookbookName{
    [self sendCookbookNotifyMessageToDeviceWithCookbookName:cookbookName WithContent:@"启动菜谱播放"];
}

//结束菜谱播放通知
- (void)sendStopCookbookPlayNotifyWithCookbookName:(NSString *)cookbookName{
    [self sendCookbookNotifyMessageToDeviceWithCookbookName:cookbookName WithContent:@"结束菜谱播放"];
}

- (NSData *)transforToData:(NSDictionary *)dict {
    
    NSString *json = [self transforToJsonString:dict];
    json = [self deleteSpecialCodeWithStr:json];
    NSData *jsonData = [json dataUsingEncoding:NSUTF8StringEncoding];
    return jsonData;
}
- (NSString*)transforToJsonString:(NSDictionary *)dict {
    NSError *parseError = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&parseError];
    return [[NSString alloc] initWithData:jsonData encoding:
            NSUTF8StringEncoding];
}

#pragma mark -- 处理json格式的字符串中的换行符、回车符
- (NSString *)deleteSpecialCodeWithStr:(NSString *)str {
    NSString *string = [str stringByReplacingOccurrencesOfString:@"\r" withString:@""];
    string = [string stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    string = [string stringByReplacingOccurrencesOfString:@"\r\n" withString:@""];
    string = [string stringByReplacingOccurrencesOfString:@"\t" withString:@""];
    string = [string stringByReplacingOccurrencesOfString:@" " withString:@""];
    string = [string stringByReplacingOccurrencesOfString:@"(" withString:@""];
    string = [string stringByReplacingOccurrencesOfString:@")" withString:@""];
    return string;
}
#pragma mark - 其他功能
- (void)pushToMainControllerWithNavigationController:(UINavigationController *)navigationController{
}

#pragma mark---配置虚拟设备信息
- (void)configVirtualAllDeviceWithUint8_t:(uint8_t *)dataPoint {
    
}

- (void)configVirtualDeviceWithUint8_t:(uint8_t *)dataPoint {
    
}
@end

